commonApp.factory("reference", ["upserve", "ngDialog", function (upserve, ngDialog) {
	var reference = {
		personReference:function(callBack){
			var dialog = ngDialog.open({
				templateUrl: $path$ +  "/public/template/Help_Person_Conditionfilter.html",
				width:650,
				controller:['$scope', 'upserve', function($scope, upserve){
					$scope.data = {};
					$scope.grid = {};
					$scope.columns = [
	                    {field:'PersonCode',title:'职员编号',width:100 , hidden:false},
					 	{field:'PersonName ',title:'职员名称',width:100 , hidden:false},
					 	{field:'DeptName ',title:'部门',width:100 , hidden:false}
					];
					$scope.options = {
					 	resizable:true,
					 	sortable: true,
					 	selectable:true,
					 	height: 300,
					 	pageable:true,
					 	groupable:false,
					 	columns:$scope.columns,
					 	change:function(){
					 		$scope.data = this.dataItem(this.select()[0]);
					 	},
					 	dataBound:function(e){
					 		var grid = this;
					 		angular.element(this.tbody).find('tr').dblclick(function(e, grid){
					 			$scope.ok();
					 		});
					 	}
					 };
					
					 $scope.dataSource = new kendo.data.DataSource({
					 	data:[],
					 	page: 1,
					 	pageSize: 10
					});
					 
					 $scope.queryData = function(keyword){
						 if(keyword==''||keyword==undefined){
							 url = $path$ + '/admin/getHelpPersonConditionfilter?key=';
						 }else{
							 url = $path$ +  '/admin/getHelpPersonConditionfilter?key=' + encodeURI(keyword);
						 }
						 upserve.get({
			                 url: url,
			                 success: function (data) {
			                	 $scope.dataSource.data(data);
			                 }
						 });
					 };
					 
					 $scope.queryData('');
					 $scope.ok = function(){
						 dialog.close();
						 callBack($scope.data);
					 }
					 $scope.cancel = function(){
						 dialog.close();
					 }
				}]
			});
		},
		vendorReference:function(callBack){
			var dialog = ngDialog.open({
				templateUrl: $path$ + "/public/template/Help_Vendor_Conditionfilter.html",
				width:650,
				controller:['$scope', 'upserve', function($scope, upserve){
					$scope.data = {};
					$scope.grid = {};
					
					$scope.columns = [
	                    {field:'VendorCode',title:'供应商编码',width:100 , hidden:false},
					 	{field:'VendorName ',title:'供应商名称',width:100 , hidden:false}
					];
					
					$scope.options = {
					 	resizable:true,
					 	sortable: true,
					 	selectable:true,
					 	height: 300,
					 	pageable:true,
					 	groupable:false,
					 	columns:$scope.columns,
					 	change:function(){
					 		$scope.data = this.dataItem(this.select()[0]);
					 	},
					 	dataBound:function(e){
					 		var grid = this;
					 		angular.element(this.tbody).find('tr').dblclick(function(e, grid){
					 			$scope.ok();
					 		});
					 	}
					 };
					
					 $scope.dataSource = new kendo.data.DataSource({
					 	data:[],
					 	page: 1,
					 	pageSize: 10
					});
					 
					 $scope.queryVendorData = function(keyword){
						 if(keyword==''||keyword==undefined){
							 url = $path$ + '/admin/getHelpVendorConditionfilter?key=';
						 }else{
							 url = $path$ + '/admin/getHelpVendorConditionfilter?key=' + encodeURI(keyword);
						 }
						 upserve.get({
			                 url: url,
			                 success: function (data) {
			                	 $scope.dataSource.data(data);
			                 }
						 });
					 };
					 
					 $scope.queryVendorData('');
					 $scope.ok = function(){
						 dialog.close();
						 callBack($scope.data);
					 }
					 $scope.cancel = function(){
						 dialog.close();
					 }
				}]
			});
		},
		supplierReference:function(callBack){
			var dialog = ngDialog.open({
				templateUrl: $path$ + "/public/template/Help_Supplier_Conditionfilter.html",
				width:650,
				controller:['$scope', 'upserve', function($scope, upserve){
					$scope.data = {};
					$scope.grid = {};
					
					$scope.columns = [
	                    {field:'SupplierCode',title:'供应商编码',width:100 , hidden:false},
					 	{field:'SupplierName ',title:'供应商名称',width:100 , hidden:false}
					];
					
					$scope.options = {
					 	resizable:true,
					 	sortable: true,
					 	selectable:true,
					 	height: 300,
					 	pageable:true,
					 	groupable:false,
					 	columns:$scope.columns,
					 	change:function(){
					 		$scope.data = this.dataItem(this.select()[0]);
					 	},
					 	dataBound:function(e){
					 		var grid = this;
					 		angular.element(this.tbody).find('tr').dblclick(function(e, grid){
					 			$scope.ok();
					 		});
					 	}
					 };
					
					 $scope.dataSource = new kendo.data.DataSource({
					 	data:[],
					 	page: 1,
					 	pageSize: 10
					});
					 
					 $scope.queryVendorData = function(keyword){
						 if(keyword==''||keyword==undefined){
							 url =$path$ +  '/admin/getHelpSupplierConditionfilter?key=';
						 }else{
							 url = $path$ + '/admin/getHelpSupplierConditionfilter?key=' + encodeURI(keyword);
						 }
						 upserve.get({
			                 url: url,
			                 success: function (data) {
			                	 $scope.dataSource.data(data);
			                 }
						 });
					 };
					 
					 $scope.queryVendorData('');
					 $scope.ok = function(){
						 dialog.close();
						 callBack($scope.data);
					 }
					 $scope.cancel = function(){
						 dialog.close();
					 }
				}]
			});
		},
		wareHouseReference:function(callBack){
			var dialog = ngDialog.open({
				templateUrl: $path$ + "/public/template/Help_WareHouse_Conditionfilter.html",
				width:650,
				controller:['$scope', 'upserve', function($scope, upserve){
					$scope.grid = {};
					$scope.data = {};
					$scope.columns = [
	                    {field:'WareHouseCode',title:'仓库编码',width:100 , hidden:false},
					 	{field:'WareHouseName ',title:'仓库名称',width:100 , hidden:false}
					];
					
					$scope.options = {
					 	resizable:true,
					 	sortable: true,
					 	selectable:true,
					 	height: 300,
					 	pageable:true,
					 	groupable:false,
					 	columns:$scope.columns,
					 	change:function(){
					 		$scope.data = this.dataItem(this.select()[0]);
					 	},
					 	dataBound:function(e){
					 		var grid = this;
					 		angular.element(this.tbody).find('tr').dblclick(function(e, grid){
					 			$scope.ok();
					 		});
					 	}
					 };
					
					 $scope.dataSource = new kendo.data.DataSource({
					 	data:[],
					 	page: 1,
					 	pageSize: 10
					});
					 
					 $scope.queryData = function(keyword){
						 if(keyword==''||keyword==undefined){
							 url = $path$ + '/admin/getHelpWareHouseConditionfilter?key=';
						 }else{
							 url = $path$ + '/admin/getHelpWareHouseConditionfilter?key=' + encodeURI(keyword);
						 }
						 upserve.get({
			                 url: url,
			                 success: function (data) {
			                	 $scope.dataSource.data(data);
			                 }
						 });
					 };
					 
					 $scope.queryData('');
					 $scope.ok = function(){
						 callBack($scope.data);
						 dialog.close();
					 }
					 $scope.cancel = function(){
						 dialog.close();
					 }
				}]
			});
		},
		departmentReference:function(callBack){
			var dialog = ngDialog.open({
				templateUrl: $path$ + "/public/template/Help_Department_Conditionfilter.html",
				width:650,
				controller:['$scope', 'upserve', function($scope, upserve){
					$scope.grid = {};
					$scope.data = {};
					$scope.columns = [
	                    {field:'DeptCode',title:'部门编码',width:100 , hidden:false},
					 	{field:'DeptName',title:'部门名称',width:100 , hidden:false}
					];
					
					$scope.options = {
					 	resizable:true,
					 	sortable: true,
					 	selectable:true,
					 	height: 300,
					 	pageable:true,
					 	groupable:false,
					 	columns:$scope.columns,
					 	change:function(){
					 		$scope.data = this.dataItem(this.select()[0]);
					 	},
					 	dataBound:function(e){
					 		var grid = this;
					 		angular.element(this.tbody).find('tr').dblclick(function(e, grid){
					 			$scope.ok();
					 		});
					 	}
					 };
					
					 $scope.dataSource = new kendo.data.DataSource({
					 	data:[],
					 	page: 1,
					 	pageSize: 10
					});
					 
					 $scope.queryData = function(keyword){
						 if(keyword==''||keyword==undefined){
							 url = $path$ + '/admin/getHelpDepartmentConditionfilter?key=';
						 }else{
							 url = $path$ + '/admin/getHelpDepartmentConditionfilter?key=' + encodeURI(keyword);
						 }
						 upserve.get({
			                 url: url,
			                 success: function (data) {
			                	 $scope.dataSource.data(data);
			                 }
						 });
					 };
					 
					 $scope.queryData('');
					 $scope.ok = function(){
						 callBack($scope.data);
						 dialog.close();
					 }
					 $scope.cancel = function(){
						 dialog.close();
					 }
				}]
			});
		},
		mulMaterialReference:function(callBack, selected){
			var dialog = ngDialog.open({
				templateUrl: $path$ + "/public/template/Help_Multiple_Material.html",
				width:1170,
				controller:['$scope', 'upserve', function($scope, upserve){
					$scope.sorts = [];
					$scope.q = {ConditionString:''};
					$scope.json = {
							MaterialSortTable : [],
							InfoTable:[]
					};
					$scope.selected = [];
					angular.forEach(selected, function(val){
						$scope.selected.push(val);
					});
					$scope.selectedGrid = {};
					
					$scope.marterialSorts = [];
					upserve.get({
						url:$path$ + '/admin/getHelpMultipleMaterialSort',
						success:function(data){
							$scope.marterialSorts = data;
						}
					});
					
					$scope.data = {};
					$scope.grid = {};
					$scope.columns = [
					     {title:'',width:30 , hidden:false, template:function(e){
							return '<a ng-click="add(dataItem)" class="arrow-right"></a>';
						}},
	                    {field:'MaterialCode',title:'货品编号',width:100 , hidden:false},
					 	{field:'MaterialSortName ',title:'货品类别',width:100 , hidden:false},
					 	{field:'MaterialName ',title:'货品名称',width:100 , hidden:false},
					 	{field:'SpeciModel ',title:'规格型号', hidden:false}
					];
					
					$scope.check = function($index, o){
						if(o.checked){
							$scope.json.MaterialSortTable.push(o);
						}else{
							angular.forEach($scope.json.MaterialSortTable, function(val, key){
								if(val.MaterialSortCode===o.MaterialSortCode){
									$scope.json.MaterialSortTable.splice(key,  1);
									return;
								}
							});
						}
					}
					$scope.options = {
					 	resizable:true,
					 	sortable: true,
					 	height: 420,
					 	pageable:{
					 		buttonCount:2
					 	},
					 	groupable:false,
					 	columns:$scope.columns,
					 };
					
					$scope.selectedDataSource =  new kendo.data.DataSource({
					 	data:$scope.selected,
					 	page: 1,
					 	pageSize: 10
					});
					
					$scope.seletedOptions = {
	                    height: 420,
	                    sortable: true,
	                    pageable:{
					 		buttonCount:2
					 	},
	                    columns:[
	                        {title:'',width:30 , hidden:false, template:function(e){
								return '<a ng-click="remove(dataItem)" class="arrow-left"></a>';
							}},
	           	            {field:'MaterialCode',title:'货品编号',width:100 , hidden:false},
	           				{field:'MaterialSortName ',title:'货品类别',width:100 , hidden:false},
	           				{field:'MaterialName ',title:'货品名称',width:100 , hidden:false},
	           			 	{field:'SpeciModel ',title:'规格型号', hidden:false}
	           			 ]
					};
					
					 $scope.dataSource = new kendo.data.DataSource({
					 	data:[],
					 	page: 1,
					 	pageSize: 10
					});
					 
					 $scope.queryData = function(keyword){
						 $scope.json.InfoTable = [];
						 $scope.q.ConditionString = keyword==undefined?'':keyword;
						 $scope.json.InfoTable.push($scope.q);
						 url = $path$ + '/admin/getHelpMultipleMaterialDetail';
						 var postData = {data:JSON.stringify($scope.json)};
						 upserve.post(url, postData, function (data) {
			                	 $scope.dataSource.data(data);
						 });
					 };
					 
					 $scope.queryData('');
					 $scope.ok = function(){
						 dialog.close();
						 callBack($scope.selected);
					 }
					 $scope.cancel = function(){
						 dialog.close();
					 }
					 $scope.add = function(e){
						var hasIt = false;
						angular.forEach($scope.selected, function(val){
							if(e.MaterialCode===val.MaterialCode){
								hasIt = true;
								return;
							}
						});
						if(hasIt){
							return;
						}
						$scope.selected.push(e);
						$scope.selectedGrid.dataSource.data($scope.selected);
					 }
					 
					 $scope.remove = function(e){
						angular.forEach($scope.selected, function(val, index){
								if(e.MaterialCode===val.MaterialCode){
									$scope.selected.splice(index, 1);
									$scope.selectedGrid.dataSource.data($scope.selected);
									return;
								}
						});
					 }
				}]
			});
		},
		materialReference:function(callBack){
			var $d=ngDialog.open({
				templateUrl: $path$ + "/public/template/Help_Material_Conditionfilter.html",
				width:650,
				controller:['$scope', 'upserve', function($scope, upserve){
					$scope.data = {};
					$scope.grid = {};
					
					$scope.columns = [
	                    {field:'MaterialCode',title:'货品编码',width:100 , hidden:false},
					 	{field:'MaterialName',title:'货品名称',width:100 , hidden:false},
					 	{field:'SpeciModel',title:'规格型号',width:100 , hidden:false},
					 	{field:'UnitName',title:'单位',width:100 , hidden:false},
					];
					
					$scope.options = {
					 	resizable:true,
					 	sortable: true,
					 	selectable:true,
					 	height: 300,
					 	pageable:true,
					 	groupable:false,
					 	columns:$scope.columns,
					 	change:function(){
					 		$scope.data = this.dataItem(this.select()[0]);
					 	},
					 	dataBound:function(e){
					 		var grid = this;
					 		angular.element(this.tbody).find('tr').dblclick(function(e, grid){
					 			$scope.ok();
					 		});
					 	}
					 };
					
					 $scope.dataSource = new kendo.data.DataSource({
					 	data:[],
					 	page: 1,
					 	pageSize: 10
					});
					 
					 $scope.queryVendorData = function(keyword){
						 if(keyword==''||keyword==undefined){
							 url = $path$ + '/admin/getHelpMaterialConditionfilter?key=';
						 }else{
							 url = $path$ + '/admin/getHelpMaterialConditionfilter?key=' + encodeURI(keyword);
						 }
						 upserve.get({
			                 url: url,
			                 success: function (data) {
			                	 $scope.dataSource.data(data);
			                 }
						 });
					 };
					 
					 $scope.queryVendorData('');
					 $scope.ok = function(){
						 $d.close();
						 callBack($scope.data);
					 }
					 $scope.cancel = function(){
						 $d.close();
					 }
				}]
			});
		},
		regionReference:function(callBack){
			var $d=ngDialog.open({
				templateUrl: $path$ + "/public/template/Help_Region_Conditionfilter.html",
				width:650,
				controller:['$scope', 'upserve', function($scope, upserve){
					$scope.data = {};
					$scope.grid = {};
					$scope.columns = [
	                    {field:'RegionCode',title:'区域编码',width:100 , hidden:false},
					 	{field:'RegionName',title:'区域名称',width:100 , hidden:false}
					];
					
					$scope.options = {
					 	resizable:true,
					 	sortable: true,
					 	selectable:true,
					 	height: 300,
					 	pageable:true,
					 	groupable:false,
					 	columns:$scope.columns,
					 	change:function(){
					 		$scope.data = this.dataItem(this.select()[0]);
					 	},
					 	dataBound:function(e){
					 		var grid = this;
					 		angular.element(this.tbody).find('tr').dblclick(function(e, grid){
					 			$scope.ok();
					 		});
					 	}
					 };
					
					 $scope.dataSource = new kendo.data.DataSource({
					 	data:[],
					 	page: 1,
					 	pageSize: 10
					});
					 
					 $scope.queryVendorData = function(keyword){
						 if(keyword==''||keyword==undefined){
							 url = $path$ + '/admin/getHelpRegionConditionfilter?key=';
						 }else{
							 url = $path$ + '/admin/getHelpRegionConditionfilter?key=' + encodeURI(keyword);
						 }
						 upserve.get({
			                 url: url,
			                 success: function (data) {
			                	 $scope.dataSource.data(data);
			                 }
						 });
					 };
					 
					 $scope.queryVendorData('');
					 $scope.ok = function(){
						 $d.close();
						 callBack($scope.data);
					 }
					 $scope.cancel = function(){
						 $d.close();
					 }
				}]
			});
		},
		tradeReference:function(callBack){
			var $d=ngDialog.open({
				templateUrl: $path$ + "/public/template/Help_Trade_Conditionfilter.html",
				width:650,
				controller:['$scope', 'upserve', function($scope, upserve){
					$scope.data = {};
					$scope.grid = {};
					$scope.columns = [
	                    {field:'TradeCode',title:'行业编码',width:100 , hidden:false},
					 	{field:'TradeName',title:'行业名称',width:100 , hidden:false}
					];
					
					$scope.options = {
					 	resizable:true,
					 	sortable: true,
					 	selectable:true,
					 	height: 300,
					 	pageable:true,
					 	groupable:false,
					 	columns:$scope.columns,
					 	change:function(){
					 		$scope.data = this.dataItem(this.select()[0]);
					 	},
					 	dataBound:function(e){
					 		var grid = this;
					 		angular.element(this.tbody).find('tr').dblclick(function(e, grid){
					 			$scope.ok();
					 		});
					 	}
					 };
					
					 $scope.dataSource = new kendo.data.DataSource({
					 	data:[],
					 	page: 1,
					 	pageSize: 10
					});
					 
					 $scope.queryVendorData = function(keyword){
						 if(keyword==''||keyword==undefined){
							 url = $path$ + '/admin/getHelpTradeConditionfilter?key=';
						 }else{
							 url = $path$ + '/admin/getHelpTradeConditionfilter?key=' + encodeURI(keyword);
						 }
						 upserve.get({
			                 url: url,
			                 success: function (data) {
			                	 $scope.dataSource.data(data);
			                 }
						 });
					 };
					 
					 $scope.queryVendorData('');
					 $scope.ok = function(){
						 $d.close();
						 callBack($scope.data);
					 }
					 $scope.cancel = function(){
						 $d.close();
					 }
				}]
			});
		},
		settleReference:function(callBack){
			var $d=ngDialog.open({
				templateUrl: $path$ + "/public/template/Help_Settle_Conditionfilter.html",
				width:650,
				controller:['$scope', 'upserve', function($scope, upserve){
					$scope.data = {};
					$scope.grid = {};
					$scope.columns = [
	                    {field:'SettleCode',title:'结算方式编码',width:100 , hidden:false},
					 	{field:'SettleName',title:'结算方式名称',width:100 , hidden:false}
					];
					
					$scope.options = {
					 	resizable:true,
					 	sortable: true,
					 	selectable:true,
					 	height: 300,
					 	pageable:true,
					 	groupable:false,
					 	columns:$scope.columns,
					 	change:function(){
					 		$scope.data = this.dataItem(this.select()[0]);
					 	},
					 	dataBound:function(e){
					 		var grid = this;
					 		angular.element(this.tbody).find('tr').dblclick(function(e, grid){
					 			$scope.ok();
					 		});
					 	}
					 };
					
					 $scope.dataSource = new kendo.data.DataSource({
					 	data:[],
					 	page: 1,
					 	pageSize: 10
					});
					 
					 $scope.queryVendorData = function(keyword){
						 if(keyword==''||keyword==undefined){
							 url = $path$ + '/admin/getHelpSettleConditionfilter?key=';
						 }else{
							 url = $path$ + '/admin/getHelpSettleConditionfilter?key=' + encodeURI(keyword);
						 }
						 upserve.get({
			                 url: url,
			                 success: function (data) {
			                	 $scope.dataSource.data(data);
			                 }
						 });
					 };
					 $scope.queryVendorData('');
					 $scope.ok = function(){
						 $d.close();
						 callBack($scope.data);
					 }
					 $scope.cancel = function(){
						 $d.close();
					 }
				}]
			});
		},
		transferWayReference:function(callBack){
			var $d=ngDialog.open({
				templateUrl: $path$ + "/public/template/Help_TransferWay_Conditionfilter.html",
				width:650,
				controller:['$scope', 'upserve', function($scope, upserve){
					$scope.data = {};
					$scope.grid = {};
					$scope.columns = [
	                    {field:'TransferWayCode',title:'运输方式编码',width:100 , hidden:false},
					 	{field:'TransferWayName',title:'运输方式名称',width:100 , hidden:false}
					];
					
					$scope.options = {
					 	resizable:true,
					 	sortable: true,
					 	selectable:true,
					 	height: 300,
					 	pageable:true,
					 	groupable:false,
					 	columns:$scope.columns,
					 	change:function(){
					 		$scope.data = this.dataItem(this.select()[0]);
					 	},
					 	dataBound:function(e){
					 		var grid = this;
					 		angular.element(this.tbody).find('tr').dblclick(function(e, grid){
					 			$scope.ok();
					 		});
					 	}
					 };
					
					 $scope.dataSource = new kendo.data.DataSource({
					 	data:[],
					 	page: 1,
					 	pageSize: 10
					});
					 
					 $scope.queryVendorData = function(keyword){
						 if(keyword==''||keyword==undefined){
							 url = $path$ + '/admin/getHelpTransferWayConditionfilter?key=';
						 }else{
							 url = $path$ + '/admin/getHelpTransferWayConditionfilter?key=' + encodeURI(keyword);
						 }
						 upserve.get({
			                 url: url,
			                 success: function (data) {
			                	 $scope.dataSource.data(data);
			                 }
						 });
					 };
					 $scope.queryVendorData('');
					 $scope.ok = function(){
						 $d.close();
						 callBack($scope.data);
					 }
					 $scope.cancel = function(){
						 $d.close();
					 }
				}]
			});
		},
		paymentTermReference:function(callBack){
			var $d=ngDialog.open({
				templateUrl: $path$ + "/public/template/Help_PaymentTerm_Conditionfilter.html",
				width:650,
				controller:['$scope', 'upserve', function($scope, upserve){
					$scope.data = {};
					$scope.grid = {};
					$scope.columns = [
	                    {field:'PaymentTermCode',title:'付款条件编码',width:100 , hidden:false},
					 	{field:'PaymentTermName',title:'付款条件名称',width:100 , hidden:false}
					];
					
					$scope.options = {
					 	resizable:true,
					 	sortable: true,
					 	selectable:true,
					 	height: 300,
					 	pageable:true,
					 	groupable:false,
					 	columns:$scope.columns,
					 	change:function(){
					 		$scope.data = this.dataItem(this.select()[0]);
					 	},
					 	dataBound:function(e){
					 		var grid = this;
					 		angular.element(this.tbody).find('tr').dblclick(function(e, grid){
					 			$scope.ok();
					 		});
					 	}
					 };
					
					 $scope.dataSource = new kendo.data.DataSource({
					 	data:[],
					 	page: 1,
					 	pageSize: 10
					});
					 
					 $scope.queryVendorData = function(keyword){
						 if(keyword==''||keyword==undefined){
							 url = $path$ + '/admin/getHelpPaymentTermConditionfilter?key=';
						 }else{
							 url = $path$ + '/admin/getHelpPaymentTermConditionfilter?key=' + encodeURI(keyword);
						 }
						 upserve.get({
			                 url: url,
			                 success: function (data) {
			                	 $scope.dataSource.data(data);
			                 }
						 });
					 };
					 $scope.queryVendorData('');
					 $scope.ok = function(){
						 $d.close();
						 callBack($scope.data);
					 }
					 $scope.cancel = function(){
						 $d.close();
					 }
				}]
			});
		},
		billingTypeReference:function(callBack){
			var $d=ngDialog.open({
				templateUrl: $path$ + "/public/template/Help_BillingType_Conditionfilter.html",
				width:650,
				controller:['$scope', 'upserve', function($scope, upserve){
					$scope.data = {};
					$scope.grid = {};
					$scope.columns = [
	                    {field:'BillingTypeCode',title:'开票类型编码',width:100 , hidden:false},
					 	{field:'BillingTypeName',title:'开票类型名称',width:100 , hidden:false}
					];
					
					$scope.options = {
					 	resizable:true,
					 	sortable: true,
					 	selectable:true,
					 	height: 300,
					 	pageable:true,
					 	groupable:false,
					 	columns:$scope.columns,
					 	change:function(){
					 		$scope.data = this.dataItem(this.select()[0]);
					 	},
					 	dataBound:function(e){
					 		var grid = this;
					 		angular.element(this.tbody).find('tr').dblclick(function(e, grid){
					 			$scope.ok();
					 		});
					 	}
					 };
					
					 $scope.dataSource = new kendo.data.DataSource({
					 	data:[],
					 	page: 1,
					 	pageSize: 10
					});
					 
					 $scope.queryVendorData = function(keyword){
						 if(keyword==''||keyword==undefined){
							 url = $path$ + '/admin/getHelpBillingTypeConditionfilter?key=';
						 }else{
							 url = $path$ + '/admin/getHelpBillingTypeConditionfilter?key=' + encodeURI(keyword);
						 }
						 upserve.get({
			                 url: url,
			                 success: function (data) {
			                	 $scope.dataSource.data(data);
			                 }
						 });
					 };
					 $scope.queryVendorData('');
					 $scope.ok = function(){
						 $d.close();
						 callBack($scope.data);
					 }
					 $scope.cancel = function(){
						 $d.close();
					 }
				}]
			});
		},
		supplierSortReference:function(callBack){
			var $d=ngDialog.open({
				templateUrl: $path$ + "/public/template/Help_SupplierSort_Conditionfilter.html",
				width:650,
				controller:['$scope', 'upserve', function($scope, upserve){
					$scope.data = {};
					$scope.grid = {};
					$scope.columns = [
	                    {field:'SupplierSortCode',title:'供应商分类编号',width:100 , hidden:false},
					 	{field:'SupplierSortName',title:'供应商分类名称',width:100 , hidden:false}
					];
					
					$scope.options = {
					 	resizable:true,
					 	sortable: true,
					 	selectable:true,
					 	height: 300,
					 	pageable:true,
					 	groupable:false,
					 	columns:$scope.columns,
					 	change:function(){
					 		$scope.data = this.dataItem(this.select()[0]);
					 	},
					 	dataBound:function(e){
					 		var grid = this;
					 		angular.element(this.tbody).find('tr').dblclick(function(e, grid){
					 			$scope.ok();
					 		});
					 	}
					 };
					
					 $scope.dataSource = new kendo.data.DataSource({
					 	data:[],
					 	page: 1,
					 	pageSize: 10
					});
					 
					 $scope.queryVendorData = function(keyword){
						 if(keyword==''||keyword==undefined){
							 url = $path$ + '/admin/getHelpSupplierSortConditionfilter?key=';
						 }else{
							 url = $path$ + '/admin/getHelpSupplierSortConditionfilter?key=' + encodeURI(keyword);
						 }
						 upserve.get({
			                 url: url,
			                 success: function (data) {
			                	 $scope.dataSource.data(data);
			                 }
						 });
					 };
					 $scope.queryVendorData('');
					 $scope.ok = function(){
						 $d.close();
						 callBack($scope.data);
					 }
					 $scope.cancel = function(){
						 $d.close();
					 }
				}]
			});
		},
		materialSortReference:function(callBack){
			var $d=ngDialog.open({
				templateUrl: $path$ + "/public/template/Help_MaterialSort_Conditionfilter.html",
				width:650,
				controller:['$scope', 'upserve', function($scope, upserve){
					$scope.data = {};
					$scope.grid = {};
					$scope.columns = [
	                    {field:'MaterialSortCode',title:'货品分类编号',width:100 , hidden:false},
					 	{field:'MaterialSortName',title:'货品分类名称',width:100 , hidden:false}
					];
					
					$scope.options = {
					 	resizable:true,
					 	sortable: true,
					 	selectable:true,
					 	height: 300,
					 	pageable:true,
					 	groupable:false,
					 	columns:$scope.columns,
					 	change:function(){
					 		$scope.data = this.dataItem(this.select()[0]);
					 	},
					 	dataBound:function(e){
					 		var grid = this;
					 		angular.element(this.tbody).find('tr').dblclick(function(e, grid){
					 			$scope.ok();
					 		});
					 	}
					 };
					
					 $scope.dataSource = new kendo.data.DataSource({
					 	data:[],
					 	page: 1,
					 	pageSize: 10
					});
					 
					 $scope.queryMaterialSotData = function(keyword){
						 if(keyword==''||keyword==undefined){
							 url = $path$ + '/admin/getHelpMaterialSortConditionfilter?key=';
						 }else{
							 url = $path$ + '/admin/getHelpMaterialSortConditionfilter?key=' + encodeURI(keyword);
						 }
						 upserve.get({
			                 url: url,
			                 success: function (data) {
			                	 $scope.dataSource.data(data);
			                 }
						 });
					 };
					 $scope.queryMaterialSotData('');
					 $scope.ok = function(){
						 $d.close();
						 callBack($scope.data);
					 }
					 $scope.cancel = function(){
						 $d.close();
					 }
				}]
			});
		},
		mulVendorReference:function(callBack, selected){
			var dialog = ngDialog.open({
				templateUrl: $path$ + "/public/template/Help_Multiple_Vendor.html",
				width:1170,
				controller:['$scope', 'upserve', function($scope, upserve){
					$scope.sorts = [];
					$scope.q = {ConditionString:''};
					$scope.json = {
							VendorSortTable : [],
							InfoTable:[]
					};
					$scope.selected = [];
					angular.forEach(selected, function(val){
						$scope.selected.push(val);
					});
					$scope.selectedGrid = {};
					
					$scope.vendorSorts = [];
					upserve.get({
						url:$path$ + '/admin/getHelpMultipleVendorSort',
						success:function(data){
							$scope.vendorSorts = data;
						}
					});
					
					$scope.data = {};
					$scope.grid = {};
					$scope.columns = [
					     {title:'',width:30 , hidden:false, template:function(e){
							return '<a ng-click="add(dataItem)" class="arrow-right"></a>';
						}},
	                    {field:'VendorCode',title:'供应商编号',width:100 , hidden:false},
					 	{field:'VendorName ',title:'供应商名称',width:200 , hidden:false},
					];
					
					$scope.check = function($index, o){
						if(o.checked){
							$scope.json.VendorSortTable.push(o);
						}else{
							angular.forEach($scope.json.VendorSortTable, function(val, key){
								if(val.VenderSortCode===o.VenderSortCode){
									$scope.json.VendorSortTable.splice(key,  1);
									return;
								}
							});
						}
					}
					$scope.options = {
					 	resizable:true,
					 	sortable: true,
					 	height: 420,
					 	pageable:{
					 		buttonCount:2
					 	},
					 	groupable:false,
					 	columns:$scope.columns,
					 };
					
					$scope.selectedDataSource =  new kendo.data.DataSource({
					 	data:$scope.selected,
					 	page: 1,
					 	pageSize: 10
					});
					
					$scope.seletedOptions = {
	                    height: 420,
	                    sortable: true,
	                    pageable:{
					 		buttonCount:2
					 	},
	                    columns:[
	                        {title:'',width:30 , hidden:false, template:function(e){
								return '<a ng-click="remove(dataItem)" class="arrow-left"></a>';
							}},
	           	            {field:'VendorCode',title:'供应商编号',width:100 , hidden:false},
	           				{field:'VendorName ',title:'供应商名称',width:200 , hidden:false},
	           			 ]
					};
					
					 $scope.dataSource = new kendo.data.DataSource({
					 	data:[],
					 	page: 1,
					 	pageSize: 10
					});
					 
					 $scope.queryData = function(keyword){
						 $scope.json.InfoTable = [];
						 $scope.q.ConditionString = keyword==undefined?'':keyword;
						 $scope.json.InfoTable.push($scope.q);
						 url = $path$ + '/admin/getHelpMultipleVendorDetail';
						 var postData = {data:JSON.stringify($scope.json)};
						 upserve.post(url, postData, function (data) {
			                	 $scope.dataSource.data(data);
						 });
					 };
					 
					 $scope.queryData('');
					 $scope.ok = function(){
						 dialog.close();
						 callBack($scope.selected);
					 }
					 $scope.cancel = function(){
						 dialog.close();
					 }
					 $scope.add = function(e){
						var hasIt = false;
						angular.forEach($scope.selected, function(val){
							if(e.VendorCode===val.VendorCode){
								hasIt = true;
								return;
							}
						});
						if(hasIt){
							return;
						}
						$scope.selected.push(e);
						$scope.selectedGrid.dataSource.data($scope.selected);
					 }
					 
					 $scope.remove = function(e){
						angular.forEach($scope.selected, function(val, index){
								if(e.VendorCode===val.VendorCode){
									$scope.selected.splice(index, 1);
									$scope.selectedGrid.dataSource.data($scope.selected);
									return;
								}
						});
					 }
				}]
			});
		}
	};
	return reference;
}]);
